'''
Created on Mar 18, 2012

@author: phuongdongbk
'''

import math
import random
import time

def is_fibo(n):
    num1 = 5*n*n +4
    num2 = 5*n*n -4
    if math.sqrt(num1)*math.sqrt(num1) == num1 or math.sqrt(num2)*math.sqrt(num2) == num2:
        return True
    return False

def coroutine(func):
    def start(*args, **kwargs):
        cr = func(*args, **kwargs)
        cr.next()
        return cr
    return start


def producer():
    time.sleep(1)
    r = random.randint(1, 1000)
    envelope = consumer(r)
    envelope.send(r)

@coroutine
def consumer(randomNum):
    print "Checking ", randomNum
    while True:        
        number = (yield)
        if is_fibo(number):
            print "%d is fibonacci number\n" % number
        else:
            print "%d isn't fibonacci number\n" % number
                
'''Main for running'''
while True:
    producer()
